﻿function modalAlert(ModalBody) {
    $.get("/Modal/Alert/?body=" + escape(ModalBody)
        + "&gmt=" + Math.random(), function (data) {
            $("#modalBox .modal-content").html(data);
            $("#modalBox").modal("show");
        });
}
//-------------------------------------------------------------------------
function modalDateYMD(ctl, title, def, st, ed) {
    $.get("/Modal/DateYMD/?ctl=" + ctl + "&title=" + escape(title)
        + "&def=" + escape(def) + "&st=" + escape(st) + "&ed=" + escape(ed) + "&gmt=" + Math.random(), function (data) {
            $("#modalBox .modal-content").html(data);
            $("#modalBox").modal("show");
        });
}
function modalDateYM(ctl, title, def, st, ed) {
    $.get("/Modal/DateYM/?ctl=" + ctl + "&title=" + escape(title)
        + "&def=" + escape(def) + "&st=" + escape(st) + "&ed=" + escape(ed) + "&gmt=" + Math.random(), function (data) {
            $("#modalBox .modal-content").html(data);
            $("#modalBox").modal("show");
        });
}
function modalDateChange(DateType, AltNum) {
    var v;
    switch (DateType) {
        case "year":
            v = $("#modalYear").val();
            if (isNaN(v)) { v = 2000; }
            v = parseInt(v) + AltNum;
            $("#modalYear").val(v);
            break;
        case "month":
            v = $("#modalMonth").val();
            if (isNaN(v)) { v = 1; }
            v = parseInt(v) + AltNum;
            if (v > 12) { v = 1; }
            if (v < 1) { v = 12; }
            if (v < 10) { v = "0" + v; }
            $("#modalMonth").val(v);
            break;
        case "day":
            v = $("#modalDay").val();
            if (isNaN(v)) { v = 1; }
            v = parseInt(v) + AltNum;
            if (v > 31) { v = 1; }
            if (v < 1) { v = 31; }
            if (v < 10) { v = "0" + v; }
            $("#modalDay").val(v);
            break;
    }
}
function modalDateYMDPicked() {
    var modalYear = $("#modalYear").val();
    var modalMonth = $("#modalMonth").val();
    var modalDay = $("#modalDay").val();
    //验证年月日是数字，并且位数正确
    if (isNaN(modalYear)) {
        $("#modalDateCaution").html("您选择的并不是一个正确的日期，请重新选择");
        return;
    }
    if (isNaN(modalMonth)) {
        $("#modalDateCaution").html("您选择的并不是一个正确的日期，请重新选择");
        return;
    }
    if (isNaN(modalDay)) {
        $("#modalDateCaution").html("您选择的并不是一个正确的日期，请重新选择");
        return;
    }
    //
    var intModalYear = parseInt(modalYear);
    var intModalMonth = parseInt(modalMonth);
    var intModalDay = parseInt(modalDay);
    if (intModalYear <= 1900) {
        $("#modalDateCaution").html("您需要填写一个正确的年份");
        return;
    }
    if (intModalMonth <= 0 && intModalMonth > 12) {
        $("#modalDateCaution").html("您填写的月份应介于1至12之间");
        return;
    }
    if (intModalDay <= 0 && intModalDay > 31) {
        $("#modalDateCaution").html("您填写的日期应介于1至31之间");
        return;
    }
    //
    if (modalMonth.length == 1) { modalMonth = "0" + modalMonth; }
    if (modalDay.length == 1) { modalDay = "0" + modalDay; }
    //
    var selDate = modalYear + "-" + modalMonth + "-" + modalDay;
    var modalDateMin = $("#modalDateMin").val();
    var modalDateMax = $("#modalDateMax").val();

    if (validIsDate(modalYear, modalMonth, modalDay)) {
        if (modalDateMin != "") {
            if (!validIsDatePeriod(modalDateMin, selDate)) {
                $("#modalDateCaution").html("您选择日期不能小于" + modalDateMin + "，请重新选择");
                return;
            }
        }
        if (modalDateMax != "") {
            if (!validIsDatePeriod(selDate, modalDateMax)) {
                $("#modalDateCaution").html("您选择日期不能大于" + modalDateMax + "，请重新选择");
                return;
            }
        }
        $("#" + $("#modalDateCtl").val()).val(selDate);
        $("#modalBox").modal("hide");
    } else {
        $("#modalDateCaution").html("您选择的并不是一个正确的日期，请重新选择");
    }
}
function modalDateYMPicked() {
    var modalYear = $("#modalYear").val();
    var modalMonth = $("#modalMonth").val();
    var modalDay = "01";
    //验证年月日是数字，并且位数正确
    if (isNaN(modalYear)) {
        $("#modalDateCaution").html("您选择的并不是一个正确的日期，请重新选择");
        return;
    }
    if (isNaN(modalMonth)) {
        $("#modalDateCaution").html("您选择的并不是一个正确的日期，请重新选择");
        return;
    }
    //
    var intModalYear = parseInt(modalYear);
    var intModalMonth = parseInt(modalMonth);
    var intModalDay = parseInt(modalDay);
    if (intModalYear <= 1900) {
        $("#modalDateCaution").html("您需要填写一个正确的年份");
        return;
    }
    if (intModalMonth <= 0 && intModalMonth > 12) {
        $("#modalDateCaution").html("您填写的月份应介于1至12之间");
        return;
    }
    //
    if (modalMonth.length == 1) { modalMonth = "0" + modalMonth; }
    //
    var selDate = modalYear + "-" + modalMonth + "-" + modalDay;
    var modalDateMin = $("#modalDateMin").val();
    var modalDateMax = $("#modalDateMax").val();

    if (validIsDate(modalYear, modalMonth, modalDay)) {
        if (modalDateMin != "") {
            if (!validIsDatePeriod(modalDateMin, selDate)) {
                $("#modalDateCaution").html("您选择日期不能小于" + modalDateMin + "，请重新选择");
                return;
            }
        }
        if (modalDateMax != "") {
            if (!validIsDatePeriod(selDate, modalDateMax)) {
                $("#modalDateCaution").html("您选择日期不能大于" + modalDateMax + "，请重新选择");
                return;
            }
        }
        $("#" + $("#modalDateCtl").val()).val(modalYear + "-" + modalMonth);
        $("#modalBox").modal("hide");
    } else {
        $("#modalDateCaution").html("您选择的并不是一个正确的日期，请重新选择");
    }
}
//-------------------------------------------------------------------------
function modalNumber(ctl, title, def, st, ed) {
    $.get("/Modal/Number/?ctl=" + ctl + "&title=" + escape(title)
        + "&def=" + escape(def) + "&st=" + escape(st) + "&ed=" + escape(ed) + "&gmt=" + Math.random(), function (data) {
            $("#modalBox .modal-content").html(data);
            $("#modalBox").modal("show");
        });
}
function modalNumberPicked() {
    var modalYear = $("#modalYear").val();
    //验证年月日是数字，并且位数正确
    if (isNaN(modalYear)) {
        $("#modalDateCaution").html("您选择的并不是一个正确的数字，请重新选择");
        return;
    }
    //
    var modalDateMin = $("#modalDateMin").val();
    var modalDateMax = $("#modalDateMax").val();
    if (modalDateMin != "") {
        if (parseInt(modalYear) < parseInt(modalDateMin)) {
            $("#modalDateCaution").html("您选择数字不能小于" + modalDateMin + "，请重新选择");
            return;
        }
    }
    if (modalDateMax != "") {
        if (parseInt(modalYear) > parseInt(modalDateMax)) {
            $("#modalDateCaution").html("您选择数字不能大于" + modalDateMax + "，请重新选择");
            return;
        }
    }
    $("#" + $("#modalDateCtl").val()).val(modalYear);
    $("#modalBox").modal("hide");
}
//-------------------------------------------------------------------------
function modalChinaCity(ctl, iscnonly) {
    $.get("/Modal/ChinaCity/?ctl=" + ctl + "&iscnonly=" + iscnonly + "&gmt=" + Math.random(), function (data) {
        $("#modalBox .modal-content").html(data);
        $("#modalBox").modal("show");
    });
}
//-------------------------------------------------------------------------
function modalWorldCity(ctl, iswdonly) {
    $.get("/Modal/WorldCity/?ctl=" + ctl + "&iswdonly=" + iswdonly + "&gmt=" + Math.random(), function (data) {
        $("#modalBox .modal-content").html(data);
        $("#modalBox").modal("show");
    });
}
//-------------------------------------------------------------------------
function modalWorkDuty(ctl) {
    $.get("/Modal/WorkDuty/?ctl=" + ctl + "&gmt=" + Math.random(), function (data) {
        $("#modalBox .modal-content").html(data);
        $("#modalBox").modal("show");
    });
}
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------
function modalDialogSelectedLeft(ctl, portal, v) {
    $("#modalBox .modalDialogLeft div").each(function (i) {
        $(this).css("background-color", "aliceblue");
        $(this).css("color", "#1c3764");
    });
    $(ctl).css("background-color", "#af8a1d");
    $(ctl).css("color", "#ffffff");
    $("#modalDialogParam2").val(v);
    $.get("/Modal/" + portal + "/?v=" + escape(v) + "&gmt=" + Math.random(), function (data) {
        $("#modalBox .modalDialogRight").html(data);
    });
}
function modalDialogSelectedRight(ctl, v) {
    $("#modalBox .modalDialogRight div").each(function (i) {
        $(this).css("background-color", "aliceblue");
        $(this).css("color", "#333");
    });
    $(ctl).css("background-color", "#af8a1d");
    $(ctl).css("color", "#ffffff");
    $("#modalDialogParam3").val(v);
}
//-------------------------------------------------------------------------
function modalDialogPicked() {
    var modalCtl1 = $("#modalDialogCtl1").val();
    var modalParam1 = $("#modalDialogParam1").val();
    var modalCtl2 = $("#modalDialogCtl2").val();
    var modalParam2 = $("#modalDialogParam2").val();
    var modalCtl3 = $("#modalDialogCtl3").val();
    var modalParam3 = $("#modalDialogParam3").val();
    //
    if (modalCtl1 != "" && modalParam1 == "") { $("#modalDateCaution").html("*请按要求选择、填写"); return; }
    if (modalCtl2 != "" && modalParam2 == "") { $("#modalDateCaution").html("*请按要求选择、填写"); return; }
    if (modalCtl3 != "" && modalParam3 == "") { $("#modalDateCaution").html("*请按要求选择、填写"); return; }
    //
    $("#" + modalCtl1).val(modalParam1);
    $("#" + modalCtl2).val(modalParam2);
    $("#" + modalCtl3).val(modalParam3);
    $("#modalBox").modal("hide");
}
//-------------------------------------------------------------------------
